package com.lyb.controller;

import com.lyb.pojo.Article;
import com.lyb.service.ArticleService;
import com.lyb.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("article")
@Tag(name = "文章接口文档")
@CrossOrigin
public class ArticleController {

    @Autowired
    private ArticleService service;

    @Operation(summary = "分页查询")
    @GetMapping("{page}/{size}")
    public Result findPage(@PathVariable int page,
                           @PathVariable int size){
        Result result = service.findPage(page, size);
        return result;
    }

    @Operation(summary = "查询全部")
    @GetMapping("list")
    public Result queryList(Integer cid){
        Result result = service.queryList(cid);
        return result;
    }

    @Operation(summary = "根据id查询详情")
    @GetMapping("{id}")
    public Result queryById(@PathVariable Integer id){
        Result result = service.queryDetail(id);
        return result;
    }

    @Operation(summary = "保存")
    @PostMapping
    public Result save(@RequestBody Article article){
        Result result = service.save(article);
        return result;
    }

    @Operation(summary = "修改")
    @PutMapping
    public Result update(@RequestBody Article article){
        Result result = service.update(article);
        return result;
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        Result result = service.delete(id);
        return result;
    }
}
